package me.magicall.web.simple.spring.util;

import me.magicall.util.kit.Kits;

public interface UrlPatternRule {

	/**
	 * 模块名字的正则式，参数名为modelName。
	 */
	String SINGULAR_MODEL_NAME = "/{modelName:\\w+[\\w^s]}";
	/**
	 * id的正则式，参数名为id。目前只支持数字
	 */
	String ID = "/{id:\\d+}";
	String MAYBE_ID = "/{id:\\d*}";
	String IDS = "/{ids:\\d+}";
	String IDS_LIST = "/{ids:[\\d+,]+}";
	String IDS_RANGE = "/{ids:\\d+~\\d+}";
	String PAGE = "/{page:\\d+}";

	public enum UrlPatternPart {

		MODEL_NAME_SINGULAR_OR_PLURAL("modelName", "\\w+"), //
//		ID("id", "\\d+"), //
//		MAYBE_ID("id", "\\d*"), //
//		IDS_LIST("ids", "\\d+[,\\d]*"), //
//		IDS_RANGE("ids", "\\d+~\\d+"), //
//		OP("", "\\w+"), //
		;
		private UrlPatternPart(final String paramName, final String regex) {
			this.paramName = paramName;
			this.regex = regex;
			if (Kits.STR.isEmpty(paramName)) {
				urlPatternRule = "/{" + regex + "}";
			} else {
				urlPatternRule = "/{" + paramName + ":" + regex + "}";
			}
		}

		public final String urlPatternRule;
		public final String paramName;
		public final String regex;
	}

}
